/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.configuration.stLuzia;

import org.ipti.br.tag.bo.ConfigurationsBO;
import org.ipti.br.tag.bo.UnityBO;
import org.ipti.br.tag.configuration.qualifiers.LocalCity;
import org.ipti.br.tag.entity.City;
import org.ipti.br.tag.entity.Unity;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;

/**
 *
 * @author luancorumba
 */
@ApplicationScoped
public class ConfigFactory {
    
    @Inject
    private ConfigurationsBO configurationsBO;
    @Inject
    private UnityBO unityBO;
    
    @LocalCity
    @Produces
    public City findLocalCity() {
        Long serial = configurationsBO.getSerialNumber();
        Unity unity = unityBO.find(serial);
        try {
            return unity.getPerson().getAddress().getZipcode().getCity();
        } catch (NullPointerException npe) {
            return null;
        }
    }
}
